const express = require("express");
const cors = require("cors");
const app = express();
const bodyParser = require("body-parser");
const menuRouter = require("./routes/menu");
const userRouter = require("./routes/user");
const loansRouter = require("./routes/loans");
const productsRouter = require("./routes/products");
const studentRouter = require("./routes/student");
const loginRouter = require("./routes/login");
const authenticateToken = require("./interceptors/authenticateToken");

// 使用jwt
app.use(authenticateToken);
// 使用cors中间件
app.use(cors());
// 使用body parser中间件
app.use(bodyParser.json()); // 解析 JSON 格式的请求体
app.use(bodyParser.urlencoded({ extended: true })); // 解析表单格式的请求体
app.use;
app.use("/", menuRouter);
app.use("/", userRouter);
app.use("/", loansRouter);
app.use("/", productsRouter);
app.use("/", studentRouter);
app.use("/", loginRouter);

const port = 3008;
app.listen(port, () => {
  console.log(`Server is running on http://localhost:${port}`);
});
